{template 'common/header'}
<div class="main">
<ul class="nav nav-tabs">
    <li {if $_GPC['do'] == 'votelist'}class="active"{/if}><a href="{php echo $this->createWebUrl('votelist');}">管理</a></li>
    <li {if $_GPC['do'] == 'voteadd'}class="active"{/if}><a href="{php echo $this->createWebUrl('voteadd');}">添加</a></li>
</ul>

<form action="" class="form-horizontal form" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$item['id']}">
    <h4>投票活动信息</h4>
    <table class="tb">
        <tr>
            <th>活动名称</th>
            <td><input type="text" id="title" name="title" value="{$item['title']}" class="span4"/></td>
        </tr>
    </table>

    <h4 class="alert-heading">投票条件设置</h4>
    <table class="tb">
        <tbody>
        <tr>
            <th>投票状态</th>
            <td>
            <span class="uneditable-input span7" style="cursor: auto;">
                <label class="radio inline">
                    <input type="radio" value="0" name="state" {if $item['state'] == 0 || empty($item['state'])}checked{/if}>开启
                </label>
                   <label class="radio inline">
                       <input type="radio" value="1" name="state" {if $item['state'] == 1}checked{/if}>关闭
                   </label>
                </span>
                </span>
                <div class="help-block">投票开关，开启才可进行投票。</div>
            </td>
        </tr>

        <tr>
            <th>投票时间</th>
            <td>
                <button style="margin:0;" class="btn span5" id="date-range" type="button">
                    <span class="date-title">{php echo date('Y-m-d H:i', $item['start_time'])} 至 {php echo date('Y-m-d H:i', $item['end_time'])}</span>
                    <i class="icon-caret-down"></i>
                </button>
                <input name="start_time" type="hidden" value="{php echo date('Y-m-d H:i', $item['start_time'])}" />
                <input name="end_time" type="hidden" value="{php echo date('Y-m-d H:i', $item['end_time'])}" />
            </td>
        </tr>
        </tbody>
    </table>

    <h4 class="alert-heading">投票票数设置</h4>
    <table class="tb">
        <tr>
            <th>投票票数</th>
            <td>

                <span class="uneditable-input span7">
                    活动期间每个粉丝总共可投票数：<input id="form-max-vote-count" type="text" value="{$item['max_vote_count']}" class="span2" name="max_vote_count" placeholder="请填入票数" onchange="Handler.MaxVoteCount()">
                </span>
                <div class="help-block">
                    (如:设置为1,则为一人只能投一票(可作为一次性活动且只能投一票))
                </div>
                <br>

                <span class="uneditable-input span7">
                    每天每个粉丝可投出最大票数：<input id="form-max-vote-day" type="text" value="{$item['max_vote_day']}" class="span2" name="max_vote_day" placeholder="请填入票数" onchange="Handler.MaxVoteDay()">
                </span>
                <div class="help-block">
                    (如:设置为1,则为单选，当设置大于2时，则自动切换为多选)
                </div>
                <br>

                <div class="help-block" style="color: orangered;">
                    以上功能组合使用，可应对多种场合。<br>
                    如：设置5天投票活动，每天限一人一票，则只需将总可投票数(第一个选项)设置为5，每天可投票数(第二个选项)设置为1即可。<br>
                    如：设置6天投票活动，每人可投最多3票，则只需将总可投票数(第一个选项)设置为3，每天可投票数(第二个选项)设置为3即可。<br>
                </div>
            </td>

        </tr>
    </table>

    <h4 class="alert-heading">请先保存投票活动后，返回管理界面再添加投票选项</h4>
    <table class="tb">
        <tr>
            <th></th>
            <td>
                <button type="submit" class="btn btn-primary span4" name="submit" value="提交">提交</button>
                <input type="hidden" name="token" value="{$_W['token']}"/>
            </td>
        </tr>

    </table>

</form>
</div>

<link type="text/css" rel="stylesheet" href="./resource/style/daterangepicker.css" />
<script type="text/javascript" src="./resource/script/daterangepicker.js"></script>
    <script type="text/javascript">
        <!--
        $(function() {

            //详细数据相关操作
            $('#date-range').daterangepicker({
                format: 'YYYY-MM-DD HH:mm',
                startDate: $(':hidden[name=start_time]').val(),
                endDate: $(':hidden[name=end_time]').val(),
                ranges: {
                    '明天': [moment(), moment().subtract('days', -1)],
                    '一周内': [moment(), moment().subtract('days', -6)],
                    '两周内': [moment(), moment().subtract('days', -13)],
                    '一个月': [moment(), moment().subtract('days', -30)]
                },
                locale: {
                    applyLabel: '确定',
                    cancelLabel: '取消',
                    fromLabel: '从',
                    toLabel: '至',
                    weekLabel: '周',
                    customRangeLabel: '日期范围',
                    daysOfWeek: moment()._lang._weekdaysMin.slice(),
                    monthNames: moment()._lang._monthsShort.slice(),
                    firstDay: 0
                },
                timePicker: true,
                timePicker12Hour: false,
                timePickerIncrement: 5
            }, function(start_time, end_time){
                $('#date-range .date-title').html(start_time.format('YYYY-MM-DD HH:mm') + ' 至 ' + end_time.format('YYYY-MM-DD HH:mm'));
                $(':hidden[name=start_time]').val(start_time.format('YYYY-MM-DD HH:mm'));
                $(':hidden[name=end_time]').val(end_time.format('YYYY-MM-DD HH:mm'));
            });

        });

        var Handler = {
            'MaxVoteDay' : function() {
                if(parseInt($('#form-max-vote-day').attr("value")) < 0) {
                    alert("每天投票最小设置为0, 表示禁止投票");
                    $('#form-max-vote-day').attr({"value":"0"});
                    return;
                }
                if(parseInt($('#form-max-vote-day').attr("value"))  > parseInt($('#form-max-vote-count').attr("value")) ) {
                    alert("每天投票数不可超过个人投票总限制数");
                    $('#form-max-vote-day').attr({"value":$('#form-max-vote-count').attr("value")});
                    return;
                }
            },
            'MaxVoteCount' : function() {
                if(parseInt($('#form-max-vote-count').attr("value")) < 0) {
                    alert("个人总投票数最小设置为0");
                    $('#form-max-vote-count').attr({"value":"0"});
                    return;
                }
                if(parseInt($('#form-max-vote-day').attr("value"))  > parseInt($('#form-max-vote-count').attr("value"))) {
                    alert("每天投票数不可超过个人投票总限制数");
                    $('#form-max-vote-day').attr({"value":$('#form-max-vote-count').attr("value")});
                    return;
                }
            }
        };
        //-->
    </script>

{template 'common/footer'}